/**
 * 
 */
define(function(require, exports, module) {

	var $ = require('jquery');
	require('tinymce/4.0.16/tinymce.min.js');
	require('jquery/jquery-file-upload/8.8.5/vendor/jquery.ui.widget.js');
	require('jquery/jquery-file-upload/8.8.5/jquery.iframe-transport.js');
	require('jquery/jquery-file-upload/8.8.5/jquery.fileupload.js');
	require('jbox');

	$('#fileupload').fileupload(
			{
				url : $CONFIG.base_url + "/common/attachment/upload/multi",
				dataType : 'json',
				formData : {
					uid : $g_user.id
				},
				add: function (e, data) {
			        var goUpload = true;
			        var uploadFile = data.files[0];
			        if (!(/\.(gif|jpg|jpeg|png)$/i).test(uploadFile.name)) {
			        	$.jBox.tip('亲~请选择正确的图片格式');
			            goUpload = false;
			        }
			        if (uploadFile.size > 1048576) { // 1mb 3145728 
			        	$.jBox.info('亲~图片太大了，最大不超过1mb哦！','友情提示');
			            goUpload = false;
			        }
			        if (goUpload == true) {
			            data.submit();
			        }
			    },
			    progressall : function(e, data) {
					var progress = parseInt(data.loaded / data.total * 100,10);
					$("#loading-load").show();
					$("#loading-load").text(progress + '%');
				},
				done : function(e, data) {
					$.each(data.result, function(index, file) {
						$("#loading-load").hide();
						var url = $CONFIG.base_url + '/common/attachment/download/' + file.id+"/300x300";
						$('.mce-btn').parent().find('.mce-textbox').val(url);
						$('.mce-btn').parent().find('.mce-textbox').attr("readonly","readonly");
						$('.mce-btn').parent().parent().parent().next().next()
						.find('.mce-abs-layout-item').keyup(function(){
							if($(this).val()>3000){
								$.jBox.tip("宽度不能大于3000！");
								$(this).val("");
							}else if($(this).val().charAt(0)=="0"){
								$(this).val("");
							}else if(isNaN($(this).val())){
								$(this).val("");
							}
						});
						
					});
				}
			});
	// 发起活动
	tinymce.init({
		selector : 'textarea#activityBackground',
		theme : "modern",
		plugins : [ "preview image table contextmenu",
		            "emoticons paste textcolor"],
		            toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
		            toolbar2: "print preview media | forecolor backcolor emoticons",
		language : 'zh_CN',
		file_browser_callback : function(field_name, url, type, win) {
			if (type == 'image') {
				$('#fileupload').click();
			}
		},
	});
	// 项目预算反馈
	tinymce.init({
		selector : 'textarea#budget_fb_Content',
		theme : "modern",
		plugins : [ "image" ],
		language : 'zh_CN',
		file_browser_callback : function(field_name, url, type, win) {
			if (type == 'image') {
				$('#fileupload').click();
			}
		}
	});
	// 项目预算反馈
	tinymce.init({
		selector : 'textarea#activitound',
		theme : "modern",
		plugins : [ "image" ],
		language : 'zh_CN',
		file_browser_callback : function(field_name, url, type, win) {
			if (type == 'image') {
				$('#fileupload').click();
			}
		}
	});
	// 执行计划反馈
	tinymce.init({
		selector : 'textarea#schedule_fb_Content',
		theme : "modern",
		plugins : [ " image " ],
		language : 'zh_CN',
		file_browser_callback : function(field_name, url, type, win) {
			if (type == 'image') {
				$('#fileupload').click();
			}
		}
	});
	
	//添加公告
	tinymce.init({
		selector : 'textarea#content',
		theme : "modern",
		plugins : [ " image " ],
		language : 'zh_CN',
		file_browser_callback : function(field_name, url, type, win) {
			if (type == 'image') {
				$('#fileupload').click();
			}
		}
	});
	
	// 项目预算反馈
	tinymce.init({
		selector : 'textarea#resume',
		width:500,		
		theme : "modern",
		plugins :  [ "preview image table contextmenu",
			            "emoticons paste textcolor"],
			            toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
			            toolbar2: "print preview media | forecolor backcolor emoticons",
		language : 'zh_CN',
		file_browser_callback : function(field_name, url, type, win) {
			if (type == 'image') {
				$('#fileupload').click();
			}
		}
	});
	
});
   
